#!/bin/bash

# 检查是否传入了年份参数
if [ -z "$1" ]; then
  echo "Usage: $0 <year>"
  exit 1
fi

# 获取年份参数
year=$1

# 检查下载文件完整性
find /home/root/$year -type f -name '*.json.gz' | xargs -I {} -P 4 gzip -v -t {} 2>&1 | tee tmp/verify_$year.txt

cat tmp/verify_$year.txt | grep -v "OK"  > tmp/error_$year.txt


cat tmp/error_$year.txt | grep ".json.gz"  | sed -e 's#.*\/home\/root/##' -e  's/:.*//g' | awk -F "/" '{print $NF}' | sed -e 's#^#https://data.gharchive.org/#' > tmp/download_$year.txt

aria2c -x 10 -i tmp/download_$year.txt --allow-overwrite -d /home/root/$year
